//
// Created by LiuYou on 2021/8/7.
//

#ifndef PROTOCOL_HPP
#define PROTOCOL_HPP


#include <cstdint>
#include "NetRadioType.hpp"


namespace NetRadio {
    static const char DEFAULT_MULTI_GROUP[] = "224.2.2.2";
    // TODO 调试时的问题 1
//    static const int DEFAULT_RCV_PORT = 1989;
    static char  DEFAULT_RCV_PORT[] = "1989";
    static const int CHANNEL_NUM = 100;
    static const int PROGRAM_LIST_CHANNEL_ID = 0;
    static const int MIN_CHANNEL_ID = 1;
    static const int MAX_CHANNEL_ID = MIN_CHANNEL_ID + CHANNEL_NUM - 1;
    /// \brief udp推荐长度: 512 ~ 64k 。
    static const int MSG_CHANNEL_MAX = 65536 - 20 - 8;
    static const int MAX_DATA = MSG_CHANNEL_MAX - sizeof( ChannelId );
    static const int MSG_PROGRAM_LIST_MAX = 65536 - 20 - 8;
    static const int MAX_ENTRY = MSG_PROGRAM_LIST_MAX - sizeof( ChannelId );

    namespace Protocol {
        struct MsgChannel {
            /// \brief must between MIN_CHANNEL_ID ~ MAX_CHANNEL_ID.
            ChannelId channelId;
            uint8_t data[1];

        }__attribute__((packed));

        struct MsgProgramListEntry {
            ChannelId channelId;
            uint16_t len;
            uint8_t description[1];

        }__attribute__((packed));

        /// \brief 节目单udp报文
        /// 1 music:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        /// 2 sport:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        /// 3 xxxxx:xxxxxxxxxxxxxxxxxxxxxxxx
        /// 4 xx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        struct MsgProgramList {
            /// \brief must be PROGRAM_LIST_CHANNEL_ID.
            ChannelId channelId;
            struct MsgProgramListEntry entry[1];

        }__attribute__((packed));

    }

}


#endif //PROTOCOL_HPP
